package cn.kgc.service.impl;

import cn.kgc.dao.NewsCategoryDao;
import cn.kgc.dao.NewsDao;
import cn.kgc.dao.impl.NewsCategoryDaoImpl;
import cn.kgc.dao.impl.NewsDaoImpl;
import cn.kgc.pojo.NewsCategory;
import cn.kgc.service.NewsCategoryService;

public class NewsCategoryServiceImpl implements NewsCategoryService {
	private NewsDao newsDao;
	private NewsCategoryDao newsCategoryDao;
	
	//好处是只有调用构造方法创建NewsCategoryServiceImpl对象的时候才创建newDao和newsCategoryDao的对象
	public NewsCategoryServiceImpl(){
		newsDao = new NewsDaoImpl();
		newsCategoryDao = new NewsCategoryDaoImpl();
	}
	
	//删除新闻分类
	public boolean deleteNewsCategory(NewsCategory newsCategory) {
		int count = newsDao.getCountByCategory(newsCategory);
		boolean flag = false;
		if(count>0){
			System.out.println("无法删除该分类，该分类下还有新闻！");
		}else{
			flag = newsCategoryDao.deleteNewsCategory(newsCategory);
		}
		return flag;
	}
}
